import {defineApplicationConfig} from '@vben/vite-config'

export default defineApplicationConfig({
  overrides: {
    // base: '/html/zioms/ziems',
    css: {
      preprocessorOptions: {
        scss: {
          api: 'modern-compiler',
        },
      },
    },
    optimizeDeps: {
      include: [
        'echarts/core',
        'echarts/charts',
        'echarts/components',
        'echarts/renderers',
        'qrcode',
        '@iconify/iconify',
        'ant-design-vue/es/locale/zh_CN',
        'ant-design-vue/es/locale/en_US',
      ],
    },
    server: {
      headers: {
        'Cache-Control': 'no-cache, no-store, must-revalidate',
        'Pragma': 'no-cache',
        'Expires': '0',
      },
      proxy: {
        '/upload': {
          target: 'http://localhost:3300/upload',
          changeOrigin: true,
          ws: true,
          rewrite: (path) => path.replace(new RegExp(`^/upload`), ''),
        },
        // 内网访问
        // '/api': {
        //   target: 'http://10.251.181.47',
        //   changeOrigin: true,
        //   ws: true,
        //   rewrite: (path) => path.replace(new RegExp(`^/api`), '/ziems/api/'),
        // },
        //  外网访问
        '/ziems-b20/api': {
          target: 'https://zifoms.boeplat.com',
          changeOrigin: true,
          ws: true,
          rewrite: (path) => path.replace(new RegExp(`^/ziems-b20/api`), '/ziems-b20/api'),
        },
        //  内网访问
        '/ziems/api': {
          target: 'http://192.168.102.80',
          changeOrigin: true,
          ws: true,
          rewrite: (path) => path.replace(new RegExp(`^/ziems/api`), '/ziems/api'),
        },
        //  内网访问
        '/api': {
          target: 'http://server.ayaojies.com.cn:801',
          changeOrigin: true,
          ws: true,
          rewrite: (path) => path.replace(new RegExp(`^/api`), '/api'),
        },
        '/mock': {
          // target: 'http://172.20.10.11:18899', //伟峰
          // target: 'http://172.20.10.11:18899',//信一
          // target: 'http://192.168.0.111:18899', //刘杰
          target: 'http://120.92.208.117:18890',
          changeOrigin: true,
          ws: true,
          // rewrite: (path) => path.replace(new RegExp(`^/api`), '/ziems/gateway/api/'),
          rewrite: (path) => path.replace(new RegExp(`^/mock`), '/api'),
        },
      },
      port: 18899,
      warmup: {
        clientFiles: ['./index.html', './src/{views,components}/*'],
      },
    },
    build: {
      rollupOptions: {
        output: {
          entryFileNames: 'js/[name].[hash].js',
          chunkFileNames: 'js/[name].[hash].js',
          assetFileNames: (assetInfo) => {
            if (assetInfo.name?.endsWith('.css')) {
              return 'css/[name].[hash][extname]';
            }
            return 'assets/[name].[hash][extname]';
          },
        },
      },
      cssCodeSplit: true,
      target: 'esnext',
      minify: 'esbuild',
    },
  },
})
